package com.example.listviewtest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.example.listviewtest.adapter.FruitAdapter;
import com.example.listviewtest.entity.Fruit;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private List<Fruit> fruitList = new ArrayList<>();
    private String[] data = {"Apple","Banana","Orange","Grape","Strawberry","Watermelon",
            "Pineapple","Mango","Kiwi","Peach","Pear","Cherry","Blueberry","Raspberry",
            "Blackberry","Plum","Lemon","Lime","Coconut","Pomegranate"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initFruits();
        FruitAdapter fruitAdapter = new FruitAdapter(MainActivity.this, R.layout.fruit_item, fruitList);
        ListView listView = findViewById(R.id.list_view);
        listView.setAdapter(fruitAdapter);
    }

    private void initFruits(){
        for (int i = 0; i < data.length; i++){
            Fruit fruit = new Fruit(data[i], R.drawable.pic0);
            fruitList.add(fruit);
        }
    }
}